﻿using Exam.infranstuctrue.Dto.Request.Exam;
using Exam.Service.Interface;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Exam.Controllers
{

    [ApiController]
    public class TestQuestionBankController : BaseController
    {
        private readonly IQuestionBankServer _questionBankServer;

        public TestQuestionBankController(IQuestionBankServer questionBankServer)
        {
            _questionBankServer = questionBankServer;
        }
        /// <summary>
        /// 获取题库列表
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="key"></param>
        /// <param name="IsPublic"></param>
        /// <param name="IsBan"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetQuestionBank(int page = 1, int limit = 10, string? key = "", int IsPublic = -1, int IsBan = -1)
        {
            key = key ?? "";
            var result = await _questionBankServer.GetQuestionBank(page, limit, key, IsPublic, IsBan);
            return Ok(result);
        }
        /// <summary>
        /// 添加题库
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddQuestionBank(QuestionBankDto dto)
        {
            var result = await _questionBankServer.AddQuestionBank(dto);
            return Ok(result);
        }
        /// <summary>
        /// 删除题库
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> DeleteQuestionBank(List<QuestionBankDto> dto)
        {
            var result = await _questionBankServer.DeleteQuestionBank(dto);
            return Ok(result);
        }
        /// <summary>
        /// 获取单个题库
        /// </summary>
        /// <param name="qbid"></param>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetEchoQuestionBank(string qbid, int page = 1, int limit = 10, string? key = "")
        {
            key = key ?? "";
            var result = await _questionBankServer.GetEchoQuestionBank(qbid, page, limit, key);
            return Ok(result);
        }
        /// <summary>
        /// 是否禁用
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> IsBan(List<QuestionBankDto> dto)
        {
            var result = await _questionBankServer.IsBan(dto);
            return Ok(result);
        }
        /// <summary>
        /// 是否发布
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> IsPublish(List<QuestionBankDto> dto)
        {
            var result = await _questionBankServer.IsPublish(dto);
            return Ok(result);
        }
        /// <summary>
        /// 修改题库
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdateQuestionBank(QuestionBankDto dto)
        {
            var result = await _questionBankServer.UpdateQuestionBank(dto);
            return Ok(result);
        }
        /// <summary>
        /// 移入试题 --自动
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ConstituteJoinQuestion(QuestionBankDto dto)
        {
            var result = await _questionBankServer.ConstituteJoinQuestion(dto);
            return Ok(result);
        }
        /// <summary>
        /// 获取题库没有的试题
        /// </summary>
        /// <param name="qbid"></param>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetQuestion(string qbid, int limit = 1, int page = 10, string? key = "")
        {
            key = key ?? "";
            var result = await _questionBankServer.GetQuestion(qbid, limit, page, key);
            return Ok(result);
        }
        /// <summary>
        /// 移入试题 --手动
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ArtificialJoinQuestion(QuestionBankDetaliDto dto)
        {
            var result = await _questionBankServer.ArtificialJoinQuestion(dto);
            return Ok(result);
        }
        /// <summary>
        /// 移除题库试题
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> RemoveQuestion(QuestionBankDetaliDto dto)
        {
            var result = await _questionBankServer.RemoveQuestion(dto);
            return Ok(result);
        }
    }
}
